<!--
 * @Description: 监听器
 * @Author: zzj
 * @Date: 2021-10-09 12:21:17
 * @LastEditors: zzj
 * @LastEditTime: 2021-10-10 17:44:23
-->
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>监听器</title>
	<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.js"></script>
	<script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
</head>
<body>
	<div id="app">
		<div>
			{{msg}}
			<input type="text" v-model="msg">
		</div>
		<div>
			{{params}}
			<input type="text" v-model="params.name">
			<input type="text" v-model="params.type">
		</div>
	</div>
	<script>
		new Vue({
			el:"#app",
			data:{
				msg:"hello 监听器",
				params:{
					name:"",
					type:""
				}
			},
			watch:{
				msg(newVal,oldVal){
					alert(newVal+ oldVal)
				},
				"params.name":function(newVal, oldVal) {
					alert(JSON.stringify(newVal)+"-"+JSON.stringify(oldVal));
				},
				params:{
					deep:true,
					handler: function (newVal, oldVal) {
						alert(JSON.stringify(newVal) + "-" + JSON.stringify(oldVal));
					},
				}
			}
		})
	</script>
</body>
</html>